using TMPro;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.UI;

public class AfterwordDialogueController : MonoBehaviour
{
    [Header("主角文本框")]
    [SerializeField] TMP_Text heroDialogueText;
    [Header("精灵文本框")]
    [SerializeField] TMP_Text elfDialogueText;
    int index, len;
    private string[,] contents = Constants.AFTERWORD_DIALOGUE_CONTENT;
    private void OnEnable()
    {
        index = 0;
        len = contents.GetLength(0);
        GetComponent<Button>().interactable = true;
        DialogueGoOn();
    }
    private void OnDisable()
    {
        index = 0;
    }
    public void DialogueGoOn()
    {
        
        if (index == len)
        {
            Debug.Log("对话已结束！");
            GetComponent<Button>().interactable = false;
            GetComponent<PlayableDirector>().Play();
            return;
        }
        string sentence = contents[index, 1];
        if (contents[index,0] == "Hero")
        {
            elfDialogueText.GetComponent<TextTypeAnimation>().FinishImmediately();
            heroDialogueText.GetComponent<TextTypeAnimation>().StartTypeAnimation(sentence, 0.025f);
        }
        else
        {
            heroDialogueText.GetComponent<TextTypeAnimation>().FinishImmediately();
            elfDialogueText.GetComponent<TextTypeAnimation>().StartTypeAnimation(sentence, 0.025f);
        }
        index++;
    }
}
